$(document).ready(function(){
    // ##### Colorbox settings #####
    $.fn.colorbox.settings.bgOpacity = "0.9";
    $("#flash").colorbox({
        href:"../content/flash.html"
    }); //iFrame content
    $("a[href='http://google.com']").colorbox({
        fixedWidth:"80%",
        fixedHeight:550,
        iframe:true
    }); //Pictures
    $("a[rel='lightbox']").colorbox({
        transition:"elastic",
        contentCurrent:"{current} / {total}"
    }); //Inline content
    $("#inline").colorbox({
        fixedWidth:"50%",
        inline:true,
        href:"#inline_example"
    });

    $("#click").click(function(){
        $('#click').css({
            "background-color":"#f00",
            "color":"#fff",
            "cursor":"inherit"
        }).text("Open this window again and this message will still be here.");
    });

    // ##### Featured slider #####
    var theInt = null;
    var $crosslink, $navthumb;
    var curclicked = 0;

    theInterval = function(cur){
        clearInterval(theInt);

        if( typeof cur != 'undefined' )
            curclicked = cur;

        $crosslink.removeClass("active-thumb");
        $navthumb.eq(curclicked).parent().addClass("active-thumb");
        $(".stripNav ul li a").eq(curclicked).trigger('click');

        theInt = setInterval(function(){
            $crosslink.removeClass("active-thumb");
            $navthumb.eq(curclicked).parent().addClass("active-thumb");
            $(".stripNav ul li a").eq(curclicked).trigger('click');
            curclicked++;
            if( 6 == curclicked )
                curclicked = 0;
        }, 6000);
    };

    $(function(){

        $("#main-photo-slider").codaSlider();
        $navthumb = $(".nav-thumb");
        $crosslink = $(".cross-link");

        $navthumb
        .click(function() {
            var $this = $(this);
            theInterval($this.parent().attr('href').slice(1) - 1);
            return false;
        });
        theInterval();
    });


    // ##### Pretty Comments
    $('textarea').prettyComments({
        maxHeight:250
    });

    // ##### Pretty input boxes
    $('input[type="text"]').addClass("idleField");
    $('input[type="text"]').focus(function() {
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
            this.value = '';
        }
        if(this.value != this.defaultValue){
            this.select();
        }
    });
    $('input[type="text"]').blur(function() {
        $(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });
        // ##### Pretty input boxes
    $('input[type="password"]').addClass("idleField");
    $('input[type="password"]').focus(function() {
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
            this.value = '';
        }
        if(this.value != this.defaultValue){
            this.select();
        }
    });
    $('input[type="password"]').blur(function() {
        $(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value) == ''){
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });
});